#pragma once
#include "StochasticAlgorithm.h"
#include "data/Example.h"

class Perceptron : public StochasticAlgorithm
{
protected:
  arma::sp_mat m_Weight;
  double m_Bias;
  double m_Rate;
protected:
  void CheckDimension(const arma::sp_mat& x);
  Perceptron() {}
public:
  Perceptron(double rate);
  virtual ~Perceptron(void);

  const arma::sp_mat& GetWeight() const { return m_Weight; }
  double GetBias() const { return m_Bias; }

  virtual double Learn(const Example& example, int iter = 0) ;
  virtual double Predict(const arma::sp_mat& x) const { return arma::dot(m_Weight, x) + m_Bias > 0 ? 1 : -1; }
  virtual void Save(const std::string& modelFile) const;

};

